package com.hzit.sb2.config;

import com.hzit.sb2.util.CacheConstants;
import com.hzit.sb2.util.CustomKeyGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.github.benmanes.caffeine.cache.CacheLoader;

@Configuration
public class CaffeineCacheConfig {

    private static final Logger logger = LoggerFactory.getLogger(CaffeineCacheConfig.class);

    @Bean
    public CacheLoader<Object, Object> createCacheLoader() {
        return new CacheLoader<Object, Object>() {
            @Override
            public Object load(Object key) throws Exception {
                logger.debug("cacheLoader load : {}", key);
                return null;
            }
        };
    }

    @Bean(CacheConstants.CUSTOM_KEY_GENERATOR)
    public KeyGenerator createMapperKeyGenerator() {
        return new CustomKeyGenerator();
    }
}